package relatorio;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;


public class relatAluno {

    private static Connection getConnection() throws
            ClassNotFoundException, SQLException {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost/biblioteca";
        String user = "root";
        String password = "123";
        Class.forName(driver);
        Connection con = (Connection) DriverManager.getConnection(url, user, password);
        return con;

    }

    public void geraRelatorio() throws SQLException, ClassNotFoundException, JRException  {
        Connection con = getConnection();
        Statement stm = (Statement) con.createStatement();
        String query = "select * from aluno order by serie,turma,numero";
        ResultSet rs = stm.executeQuery(query);
        JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);
        JasperPrint jasperPrint = JasperFillManager.fillReport("relatorio/Biblioteca.jasper", new HashMap(), jrRS);
        JasperViewer.viewReport(jasperPrint, false);





    }
}